<?php
class Phieuhang extends Zend_Db_Table_Abstract{
    protected $_name;
    protected $_primary = 'PhieuHangID';

    function __construct() {
        $this->_name = DB_PREFIX . "hoadon";
        parent::__construct();
    }

    public function getColumns() {
        $results = array('PhieuHangID', 'MaSoPhieuHang', 'NguoiLapPhieuHang', 'NguoiLayHang', 'NgayLapPhieuHang', 'NgayGiaoHang', 'LoaiPhieuHang', 'SanPhamID', 'SoLuong');
        return $results;
    }

    public function getPrimaryKey() {
        $pk = $this->_primary;
        if (is_array($pk)) {
            if (count($pk) > 0)
            return $pk[1]; // array[1] contain column name of primary key
        }
        return $this->_primary;
    }

    public function getAll() {
        $table_name = $this->_name;
        $primary_key = $this->_primary;
        if(is_array($primary_key)) {
            @$primary_key = $primary_key[1];
        }

        $select = $select = Zend_Db_Table_Abstract::select();

        $select->setIntegrityCheck(false)
            ->from(array('ph' => $table_name))
            ->joinLeft( array( 'sp' => DB_PREFIX . "sanpham"), "ph.SanPhamID = sp.SanPhamID", array('TenSanPham', 'MaSanPham'))
            //->where("$primary_key = $id")
        ;

        return $allRecords = $this->fetchAll($select);
    }
}
?>
